package com.sensor.work.consumer;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sensor.work.entity.PudongDeviceConfig;
import com.sensor.work.entity.PudongDeviceStatus;
import com.sensor.work.service.IPudongDeviceConfigService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

@Component
@RabbitListener(queues  ={"deviceInfo"})
@AllArgsConstructor
@Slf4j
public class DeviceInfoConsumer {

    @Autowired
    private IPudongDeviceConfigService deviceService;

    @RabbitHandler
    public void process(Map<String,Object> message) {
//        log.info("接收端设备消息数据{}",message);
       UpdateWrapper<PudongDeviceConfig> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("device_no",message.get("deviceId"));
        updateWrapper.set("longitu",message.get("longitude"));
        updateWrapper.set("latitude",message.get("latitude"));
        updateWrapper.set("altitude",message.get("altitude"));

        boolean update = deviceService.update(updateWrapper);
    }

}
